home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5583 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  53 lines

  1. Path: bcrkh13.bnr.ca!news
  2. From: coopeng <coopeng@bnr.ca>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Converting integer to char/string?
  5. Date: 5 Feb 1996 19:59:38 GMT
  6. Organization: NORTEL
  7. Message-ID: <4f5nja$jrg@bcrkh13.bnr.ca>
  8. References: <4f5ehf$48i@brtph500.bnr.ca>
  9. NNTP-Posting-Host: bkani3f.bnr.ca
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
  14.  
  15. borland : char *itoa(int num, const char *str,int radix);
  16.  
  17. itoa is not currently defined by the ANSI C standard.
  18.  
  19. itoa() function converts the integer "num" into its string equivalent and places the 
  20. result in the string pointed to by str.  The base of the output string is determined 
  21. by radix, (range 2 - 16).
  22.  
  23. If your compiler doesn't have itoa,  this function may help you
  24.  
  25. base 10
  26. -------
  27.  
  28. itoa(in_num,out_char)
  29. int in_num;
  30. char *out_char;
  31. {
  32. int i, count, len;
  33. char temp[10];
  34.  
  35. for ( count=0; in_num>0; count++)
  36.   i=(in_number %10);
  37.   *(temp+count)=i+'0';
  38.   in_num /=10;
  39. }
  40. *(temp+count) ='\0';
  41. len=strlen(temp);
  42. for(count=0; count<len;count++)
  43.   *(out_char +len-count-1)=*(temp+count);
  44. *(out_char+len)='\0';
  45. }
  46.  
  47. /* This code can be found in "The C Trilogy by Eric P.Bloom" */
  48.  
  49. I didn't compile this function, but this will give you an idea I hope.
  50.    
  51.  
  52.